﻿//logo事件
/// <reference path="jquery-1.3.2.js" />
///<reference path="jquery-1.3.2-vsdoc.js" />
function showLoading() {
    $("#box").fadeIn("fast");
    $("body").append("<div id='greybackground'></div>");
    var documentheight = $(document).height();
    $("#greybackground").css({ "opacity": "0.5", "height": documentheight });
}
function hideLoading() {
    $("#box").hide();
    $("#greybackground").remove();
}

$(
function() {
    var screenwidth, screenheight, mytop, getPosLeft, getPosTop
    screenwidth = $(window).width();
    screenheight = $(window).height();
    mytop = $(document).scrollTop();
    getPosLeft = screenwidth / 2 - 260;
    getPosTop = screenheight / 2 - 150;
    $("#box").css({ "left": getPosLeft, "top": getPosTop });
    $(window).resize(function() {
        screenwidth = $(window).width();
        screenheight = $(window).height();
        mytop = $(document).scrollTop();
        getPosLeft = screenwidth / 2 - 260;
        getPosTop = screenheight / 2 - 150;
        $("#box").css({ "left": getPosLeft, "top": getPosTop + mytop });
    });
    $(window).scroll(function() {
        screenwidth = $(window).width();
        screenheight = $(window).height();
        mytop = $(document).scrollTop();
        getPosLeft = screenwidth / 2 - 260;
        getPosTop = screenheight / 2 - 150;
        $("#box").css({ "left": getPosLeft, "top": getPosTop + mytop });
    });
});
//自定义logo
$(function() {
    $("input[GroupName|=logoGroup]").click(function() {
        if ($("#logo1").checked == true) {
            showLoading();
            $("#logoShow").attr("visible", "True");
            $.ajax({ url: "../WebService.asmx/getLogo", type: "POST",
                success: function(data, statusText, request) {
                    //返回数据格式（图片地址，图片名称）
                    imgString = data.text;
                    if (imgString.length == 0) {
                        $("#logoName").attr("visilbe", "True");
                        $("#logoName").text = "你还没有上传logo";
                    }
                    else {
                        imgArr = imgString.split(",");
                        if (imgArr[0].toLowerCase().indexOf(".swf") > -1) {
                            $("#logoPreview").attr("visible", "False");
                            $("#logoName").attr("visible", "True").text = imgArr[1];
                        }
                        else {
                            $("#logoPreview").attr("visible", "True").attr("src", imgArr[0]);
                            $("#logoName").attr("visible", "True").text = imgArr[1];
                        }
                    }
                },
                error: function(data, statusText, request) {
                    alert("logo" + statusText);
                }
            });
            hideLoading();
        }
        else {
            $("#logoShow").attr("visible", "False");
        }
    });

    $("#logoPic").click(function() {
        $("#upload").fadeIn("fast");
        $("body").append("<div id='greybackground'></div>");
        var documentheight = $(document).height();
        $("#greybackground").css({ "opacity": "0.5", "height": documentheight });
        $("#uploadIframe").attr("src", "../systemConfig/uploadMore.aspx?leixing=a1").attr("visible","True");
    });
    $("#logoFlash").click(function() {
        $("#upload").fadeIn("fast");
        $("body").append("<div id='greybackground'></div>");
        var documentheight = $(document).height();
        $("#greybackground").css({ "opacity": "0.5", "height": documentheight });
        $("#uploadIframe").attr("src", "../systemConfig/uploadMore.aspx?leixing=a2").attr("visible", "True");
    });
    $("#logoLib").click(function() {
        $("#library").fadeIn("fast");
        $("body").append("<div id='greybackground'></div>");
        var documentheight = $(document).height();
        $("#greybackground").css({ "opacity": "0.5", "height": documentheight });
        $("#libraryIframe").attr("src", "../systemConfig/pictureLibrary.aspx?leixing=a").attr("visible", "True");
    });

})
//自定义背景
$(function(){
$("input[GroupName|=bgGroup]").click(function() {
    if ($("#bg1").checked == true) {
        showLoading();
        $("#bgShow").attr("visible", "True");
        $.ajax({ url: "../WebService.asmx/getBg", type: "POST",
            success: function(data, statusText, request) {
                imgString = data.text;
                if (imgString.length == 0) {
                    $("#bgName").attr("visible", "True").text = "你还没有上传图片";
                }
                else {
                    imgArr = imgString.split(",");
                    $("#bgPreview").attr("visible", "True").attr("src", imgArr[0]);
                    $("#bgName").attr("visible", "True").text = imgArr[1];
                }
            },
            error: function(data, statusText, request) {
                alert(statusText);
            }

        });

        hideLoading();
    }
    else {
        $("#bgShow").attr("visible", "True");
    }
});

$("#bgPic").click(function() {
    $("#upload").fadeIn("fast");
    $("body").append("<div id='greybackground'></div>");
    var documentheight = $(document).height();
    $("#greybackground").css({ "opacity": "0.5", "height": documentheight });
    $("#uploadIframe").attr("src", "../systemConfig/uploadMore.aspx?leixing=b").attr("visible", "True");
});
$("#bgLib").click(function() {
    $("#library").fadeIn("fast");
    $("body").append("<div id='greybackground'></div>");
    var documentheight = $(document).height();
    $("#greybackground").css({ "opacity": "0.5", "height": documentheight });
    $("#libraryIframe").attr("src", "../systemConfig/pictureLibrary.aspx?leixing=b").attr("visible", "True");
});

})
//自定义首页展示
$(function() {
    $("input[GroupName|=picGroup").click(function() {
        if ($("#pic1").checked == true) {
            $("#picShow").attr("visible", "True");
            showLoading();
            $.ajax({ url: "../WebService.asmx/getPic", type: "POST",
                success: function(data, statusText, request) {
                    picString = data.text;
                    if (picString.length == 0) {
                        $("#picName1").attr("visible", "True").text = "你还没有上传图片";
                        $("#picName2").attr("visible", "False");
                        $("#picName3").attr("visible", "False");
                        $("#picName4").attr("visible", "False");
                        $("#picName5").attr("visible", "False");
                        $("#picPreview1").attr("visible", "False");
                        $("#picPreview2").attr("visible", "False");
                        $("#picPreview3").attr("visible", "False");
                        $("#picPreview4").attr("visible", "False");
                        $("#picPreview5").attr("visible", "False");
                    }
                    else {
                        picArr = picString.split(",");
                        $("#picName1").attr("visible", "True").text = picArr[1];
                        $("#picName2").attr("visible", "True").text = picArr[3];
                        $("#picName3").attr("visible", "True").text = picArr[5];
                        $("#picName4").attr("visible", "True").text = picArr[7];
                        $("#picName5").attr("visible", "True").text = picArr[9];
                        $("#picPreview1").attr("visible", "True").text = picArr[0];
                        $("#picPreview2").attr("visible", "True").text = picArr[2];
                        $("#picPreview3").attr("visible", "True").text = picArr[4];
                        $("#picPreview4").attr("visible", "True").text = picArr[6];
                        $("#picPreview5").attr("visible", "True").text = picArr[8];

                    }
                }
            ,
                error: function(data, statusText, request) {
                    alert(statusText);
                }

            });
            hideLoading();
        }
        else {
            $("#picShow").attr("visible", false);
        }
    });

    $("#picUpload").click(function() {
        $("#upload").fadeIn("fast");
        $("body").append("<div id='greybackground'></div>");
        var documentheight = $(document).height();
        $("#greybackground").css({ "opacity": "0.5", "height": documentheight });
        $("#uploadIframe").attr("src", "../systemConfig/uploadMore.aspx?leixing=c").attr("visible", "True");
    });
    $("#picLib").click(function() {
        $("#library").fadeIn("fast");
        $("body").append("<div id='greybackground'></div>");
        var documentheight = $(document).height();
        $("#greybackground").css({ "opacity": "0.5", "height": documentheight });
        $("#libraryIframe").attr("src", "../systemConfig/pictureLibrary.aspx?leixing=c").attr("visible", "True");
    });

    $("#sortStart").click(function() {
        $("#picSort").sortable();
    });
    $("#sortEnd").click(function() {
        alert("排序成功");
    });
    $("#picSave").click(function() {
        if ($("#picShow>img").length < 5) {
            alert("图片数量不足，必须达到5张");
        }
        else {
            showLoading();
            imgs = $("#picShow>img");
            imgString = "";
            for (var item in imgs) {
                imgString += item.attr("order");
            }
            imgString = imgString.substr(1, imgString.length - 1);
            $.ajax({ url: "../WebService.asmx/savePic", data: "{imgString:" + imgString + "}", type: "POST",
                successs: function(data, statusText, request) {
                    if (data.text.toLowerCase() == "true") {
                        alert("保存成功");
                    }
                    else {
                        alert("保存失败");
                    }
                },
                error: function(data, statusText, request) {
                    alert(statusText);
                }
            });
            hideLoading();
        }
    });
});



